package servlet;

import dao.UserWordDao;
import dao.impl.UserWordDaoImpl;
import entity.UserWord;
import utils.ResponseResult;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;

@WebServlet(name = "RecordServlet", urlPatterns = "/RecordServlet")

public class RecordServlet extends HttpServlet {

    //修改密码
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //说是使用多态,提高耦合度
        UserWordDao usersDao = new UserWordDaoImpl();
        // 设置响应的内容类型为 JSON
        resp.setContentType("application/json");
        //设置ContentType字段值
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        //接收参数
        Long time = Long.valueOf(req.getParameter("time"));
        Integer userId = Integer.valueOf(req.getParameter("userId"));
        Date record = new Date();//date记录当前时间即可
        UserWord userWord = new UserWord(time, record, userId);
        int i = usersDao.recordSound(userWord);

        if (i > 0) resp.getWriter().write(ResponseResult.success().toString());
        else resp.getWriter().write(ResponseResult.failure("修改失败").toString());
    }
}
